//
//  Muse_ex_doubleAndFloat.swift
//  Muse
//
//  Created by mac on 2022/12/6.
//

import UIKit

//MARK: - Double
extension Double {
    
    /// 状态栏高度
    static var statusHeight: Double {
        if #available(iOS 13.0, *) {
            let manager = UIApplication.shared.windows.first?.windowScene?.statusBarManager
            return Double(manager?.statusBarFrame.size.height ?? 20.0)
        } else {
            return UIApplication.shared.statusBarFrame.size.height
        }
    }
    
    /// 屏幕宽
    static let screenWidth = UIScreen.main.bounds.size.width
    /// 屏幕高
    static let screenHeight = UIScreen.main.bounds.size.height
    /// 是否为刘海屏
    static let isIPhoneX: Bool          = statusHeight >= 44.0
    /// 底部安全间距
    static let safe_bottom              = isIPhoneX ? 34.0 : 0
    /// 导航栏高度
    static let navi_height              = statusHeight + 44.0
    /// Tabbar 高度
    static let tabBar_height            = safe_bottom + 49.0
    /// 底部推荐距离
    static let bottomSpace              = isIPhoneX ? 34.0 : 20.0
}

//MARK: - CGFloat
extension CGFloat {
    
    /// 状态栏高度
    static var statusHeight: Double {
        if #available(iOS 13.0, *) {
            let manager = UIApplication.shared.windows.first?.windowScene?.statusBarManager
            return Double(manager?.statusBarFrame.size.height ?? 20.0)
        } else {
            return UIApplication.shared.statusBarFrame.size.height
        }
    }
    
    /// 屏幕宽
    static let screenWidth = UIScreen.main.bounds.size.width
    /// 屏幕高
    static let screenHeight = UIScreen.main.bounds.size.height
    /// 是否为刘海屏
    static let isIPhoneX: Bool          = statusHeight >= 44.0
    /// 底部安全间距
    static let safe_bottom              = isIPhoneX ? 34.0 : 0
    /// 导航栏高度
    static let navi_height              = statusHeight + 44.0
    /// Tabbar 高度
    static let tabBar_height            = safe_bottom + 49.0
    /// 底部推荐距离
    static let bottomSpace              = isIPhoneX ? 34.0 : 20.0
    
}

//MARK: - Screen Scale
extension Double {
    ///
    var Scale: Double {
        (UIScreen.main.bounds.size.height / 812.0) * self
    }
    
    func doubleToTimeString() -> String? {
        // 提取小时和分钟部分
        let hours = Int(self)
        let minutes = Int((self - Double(hours)) * 60)
        
        // 创建日期格式化器
        let dateFormatter = DateFormatter()
        dateFormatter.dateFormat = "HH:mm"
        
        // 创建日期组件
        var dateComponents = DateComponents()
        dateComponents.hour = hours
        dateComponents.minute = minutes
        
        // 获取日历实例
        let calendar = Calendar.current
        
        // 将日期组件转换为日期对象
        guard let date = calendar.date(from: dateComponents) else {
            return nil
        }
        
        // 将日期对象转换为时间字符串
        return dateFormatter.string(from: date)
    }
    
}

extension CGSize {
    
    var Scale: CGSize {
        CGSize(width: width * 1.Scale, height: height * 1.Scale)
    }
    /// Width Scale
    var w_Scale: CGSize {
        CGSize(width: width * 1.Scale, height: height)
    }
    /// Height Scale
    var h_Scale: CGSize {
        CGSize(width: width, height: height * 1.Scale)
    }
    
    var isZero: Bool {
        self.width.isZero || self.height.isZero
    }
    
}

extension CGPoint {
    
    var Scale: CGPoint {
        CGPoint(x: x * 1.Scale, y: y * 1.Scale)
    }
    
    /// x Scale
    var x_Scale: CGPoint {
        CGPoint(x: x * 1.Scale, y: y)
    }
    /// y Scale
    var y_Scale: CGPoint {
        CGPoint(x: x, y: y * 1.Scale)
    }
    
}

extension CGRect {
    
    var Scale: CGRect {
        CGRect(origin: origin.Scale, size: size.Scale)
    }
    
    var size_Scale: CGRect {
        CGRect(origin: origin, size: size.Scale)
    }
    
    var origin_Scale: CGRect {
        CGRect(origin: origin.Scale, size: size)
    }
}

